<?php 
	include("includes/connect.php");
	include("includes/function.php");

	//$petition_id = $_REQUEST["petition_id"];
	$company_name = $_REQUEST["company_name"];
	//$sum = $_REQUEST["sum"];
	$val = $_REQUEST["val"];

	

?>

<script type="text/javascript">
	$(document).ready(function(){

		$("#save_menus").click(function() {
			event.preventDefault();

			var branch_name = $("#branch_name").val();
			var bank_name = $("#bank_name").val();
			var cheque_no = $("#cheque_no").val();
			var val = "<?php echo $val; ?>";
			var company_name = "<?php echo $company_name; ?>";
			//var sum = "<?php echo $company_name; ?>";
			var task = "print";
			//alert(petition_id);
			//window.open("prtCheck.php?petition_id=" + petition_id); 
			
			
			$.ajax({
				type: "POST",
				url: "processPetition.php",
				data: { 'task': task, 'company_name': company_name, branch_name: branch_name, bank_name: bank_name, cheque_no: cheque_no, val: val },
				cach: false,
				error: function() {
					alert("ERROR !!!!");
				},
				success: function(data){
					//alert(data);
					//if(data) { $("#kob").html(data); }
					//window.location.href="index.php?pages=finance";
					window.location.href="prtCheck.php?company_name=" + company_name + "&cheque_no=" + cheque_no + "&val=" + val;
				}
			});
			

		});
	});
</script>
<?php
	$db = new myDBS;
	$db->selectDB("account");

	$result = $db->showData("bank");

	//$val = explode(",", $val);

	$sql = "SELECT SUM(inpNet) as sum FROM tbl_petition WHERE petition_id IN($val)";
	$result1 = $db->runSQL($sql);
	$rows2 = $db->fetch_object($result1);
	
?>

<p>
	<label>ชื่อบริษัท / ชื่อเจ้าหนี้</label>
	<input class="span5" type="text" id="company_name" name="company_name" value="<?php echo $company_name; ?>" readonly>
	<label>จำนวนเงิน</label>
	<input class="span3" type="text" id="sum" name="sum" value="<?php echo number_format($rows2->sum,2); ?>" readonly>
	
    <label>ธนาคาร</label>
	<select class="span5" id="bank_name" name="bank_name" >
	<?php 
		while($rows = $db->fetch_object ( $result )) {
			echo "<option>$rows->bank_name</option>";
		}
	?>

	</select>
	<label>สาขา</label>
	<select class="span4" id="branch_name" name="branch_name" >
	<?php
		$result = $db->showData("branch");

		while($rows = $db->fetch_object ( $result )) {
			echo "<option>$rows->branch_name</option>";
		}

	?>
	</select>
	<label>เลขที่เช็ค</label>
	<input class="span2" type="text" id="cheque_no" name="cheque_no">

	
</p>
<div class="form-actions">
	<button class="btn btn-primary" id="save_menus">บันทึกและพิมพ์เช็ค</button>
	<button class="btn close-dialog"><i class="icon-remove"></i> ยกเลิก</button>

</div>
